package com.gxa.controller.yhy.Patient;


import com.github.pagehelper.PageInfo;
import com.gxa.common.R;
import com.gxa.common.Status;
import com.gxa.entity.SysPatientFollow;
import com.gxa.service.PatientFollowService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


@Controller
@Api(value = "患者跟进操作功能",tags = "患者跟进所有操作功能API")
@RequiresRoles(value = {"超级管理员","院长","主任","秘书","助理"},logical = Logical.OR)
@RequestMapping("/patient/follow")
public class PatientFollowController {


    @Autowired
    PatientFollowService patientFollowService;

    @RequestMapping(value = "/findFollowList", method = RequestMethod.GET)
    @ApiOperation(value = "展示所有跟进信息", notes = "获取跟进信息", httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "代表参数格式不对"),
            @ApiResponse(code = 404, message = "代表找不到此请求"),
            @ApiResponse(code = 500, message = "代表后端代码出现异常"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页页数", paramType = "query", dataType = "String", required = true)

    })
    @ResponseBody
    /**
     * 查询所有跟进信息
     */
    public R<Object> findFollowList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize){
        R<Object> r = new R<>();
        if (currentPage != null && pageSize != null) {
            PageInfo patientFollowList = patientFollowService.getPatientFollowList(currentPage, pageSize);
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(patientFollowList);
        }else {
            r.fromStatus(Status.BAD_PAGE_PARAM);
        }

        return r;

    }
    @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
    @ApiOperation(value = "增加跟进信息", notes = "添加跟进单", httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功"),
            @ApiResponse(code = 400, message = "代表参数格式不对"),
            @ApiResponse(code = 404, message = "代表找不到此请求"),
            @ApiResponse(code = 500, message = "代表后端代码出现异常"),
    })
    @ResponseBody
    /**
     添加新的跟进信息
     */
    public R addFollow(@RequestBody @ApiParam(name = "newFollow", value = "新的跟进单", required = true) SysPatientFollow newFollow, HttpServletRequest request) {
        R r = new R<>();
        if(newFollow !=null){
            Boolean aBoolean = patientFollowService.addPatientFollow(newFollow);
            r.fromStatus(Status.SUCCESS);
        }else {
            r.setCode(500);
            r.fromStatus(Status.SYSTEM_ERROR);
        }

        return r;
    }
    @RequestMapping(value = "/findFollowByName", method = RequestMethod.GET)
    @ApiOperation(value = "查询跟进信息", notes = "查询跟进单", httpMethod = "GET", response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "代表参数格式不对"),
            @ApiResponse(code = 404, message = "代表找不到此请求"),
            @ApiResponse(code = 500, message = "代表后端代码出现异常"),
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页页数", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "name", value = "患者姓名", paramType = "query", dataType = "String", required = true)
    })
    @ResponseBody
    /**
     通过患者名字查询跟进信息
     */
    public R findFollowByName(String name,Integer currentPage, Integer pageSize){

        R r = new R<>();
        PageInfo patientByName = patientFollowService.getPatientFollowByName(name,currentPage,pageSize);
        if (name != null || !name.equals("") && patientByName != null) {

            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(patientByName);
        }else {
            r.fromStatus(Status.BAD_QUERY_PARAM);
        }

        return r;
    }

    @RequestMapping(value = "/updateFollow", method = RequestMethod.POST)
    @ApiOperation(value = "修改跟进信息", notes = "修改跟进单", httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "修改成功"),
            @ApiResponse(code = 400, message = "代表参数格式不对"),
            @ApiResponse(code = 404, message = "代表找不到此请求"),
            @ApiResponse(code = 500, message = "代表后端代码出现异常"),
    })
    @ResponseBody
    /**
     修改跟进信息
     */
    public R updateFollow(@RequestBody @ApiParam (name = "跟进修改",value = "更进单数据修改",required = true) SysPatientFollow sysPatientFollow){
        R r = new R();
        if (sysPatientFollow != null) {
            Boolean aBoolean = patientFollowService.updatePatientFollow(sysPatientFollow);
            if (aBoolean == true) {
                r.fromStatus(Status.SUCCESS);
            }
        } else {
            r.fromStatus(Status.BAD_REQUEST_PARAM);
        }
        return r;
    }

    @RequestMapping(value = "/deleteFollow", method = RequestMethod.POST)
    @ApiOperation(value = "删除跟进信息", notes = "删除跟进单", httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功"),
            @ApiResponse(code = 400, message = "代表参数格式不对"),
            @ApiResponse(code = 404, message = "代表找不到此请求"),
            @ApiResponse(code = 500, message = "代表后端代码出现异常"),
    })
    @ApiImplicitParam(name = "id", value = "患者id", paramType = "query", dataType = "String", required = true)
    @ResponseBody
    /**
     删除跟进信息
     */
    public R deleteFollow(@RequestParam("id") Integer id){
        R r = new R();
        if (id != null) {
            Boolean aBoolean = patientFollowService.delPatientFollow(id);
            if (aBoolean == true) {
                r.fromStatus(Status.SUCCESS);
            }
        }else {
            r.fromStatus(Status.BAD_REQUEST_PARAM);
        }
        return r;
    }

}
